import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

//--------组件
import Login from '../components/Login'
import Layout from '../components/layout/index.vue'
//------首页

import Home from '../pages/home/index.vue'

/**
 * import NotFound from '../pages/errorPage/404.vue'
    import Forbidden from '../pages/errorPage/403.vue'
 * 
 */

//------初始化路由
const routes = [
  {
    path: '/Login',
    name: 'Login',
    component: Login
  }
]

/*
  根据用户的权限不同，所能看到的页面和可操作性不同
  admin - > 所有页面都可以看到
  vip -> 属于vip的权限
  vips -> 更多的vip权限
*/
//------准备动态加载的路由
export const DynamicRoutes = [
  {
    path: '',
    component: Layout,
    name: 'container',
    redirect: '/home',
    meta: {
      requiresAuth: true,
      name: '首页'
    },
    children: [
      {
        path: '/home',
        component: Home,
        name: 'home',
        title: '首页',
        meta: {
          //---匹配规则
          name: "首页",
          icon: 'el-icon-s-home'
        },
        children: []
      },
    ]
  },
  // {
  //   path: '/403',
  //   component: Forbidden
  // },
  //   {
  //   path: '*',
  //   component: NotFound
  // }
]


const router = new VueRouter({
  routes
})

export default router
  